<?php 
$cs=Yii::app()->clientScript;
$cs->registerCssFile(Yii::app()->baseUrl.'/css/form.css');
$cs->registerScript('business_from_script',<<<END
$(".lab").click(function(){\$(this).prev("input[type=checkbox]").click();return false;});
function check_product_sort(){
	if(!$("#ejsvformid1").valid()) return false;
	if($("input[type=checkbox][id^=Business_product_sort]:checked").length==0){
		alert("请选择一个分类.");$("input[type=checkbox][id^=Business_product_sort]:first").focus(); return false;
	}
	return true;
}

$("form").submit(check_product_sort);
$("input[type=checkbox][id^=Business_product_sort]").click(
function(){
	$(this).siblings("input[type=checkbox]").attr('checked',false);
}
);
function get_next_area(level,change){
	if(level==1){
		code=$("#Business_province").val();
		area_id='#Business_city';
		sel_val='$model->city';
		$("#Business_city")[0].options.length=0;
		$("#Business_city")[0].options.add(new Option('请选择',''));
	}
	else if(level==2){
		code=$("#Business_city").val();
		area_id='#Business_area';
		sel_val='$model->area';
	}
	$("#Business_area")[0].options.length=0;
	$("#Business_area")[0].options.add(new Option('请选择',''));
	$.ajax({'type':'POST','url':'?r=business/get_next_area','async':false,'cache':true,'data':'code='+code,
	'success':function(date){
		json=$.parseJSON(date);
		//$(area_id)[0].options.length=0;
		$(json).each(function(n,item){\$(area_id)[0].options.add(new Option(item.name,item.code));});
		if(sel_val!=''&&change)$(area_id)[0].value=sel_val;
	}});	
	
	
}
$("#Business_province").change(function(){get_next_area(1);get_next_area(2);})
$("#Business_city").change(function(){get_next_area(2);})
get_next_area(1,2);
get_next_area(2,2);
END
);
?>
<div class="yiiForm">
<?php
	echo EHtml::form();	
	EHtml::setOptions(array('errorElement'=> 'span',));		
	EHtml::setScenario($update?'':'create');
?>
<div>注：<span class="required">*</span>为必填项</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'username'); ?>
<?php if($update):?>
<?php echo $model->username;?>
<?php else:?>
<?php echo EHtml::activeTextField($model,'username',array('size'=>16,'maxlength'=>16)); ?>
<?php endif;?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'password'); ?>
<?php echo EHtml::activePasswordField($model,'password',array('size'=>16,'maxlength'=>16)); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'repassword'); ?>
<?php echo EHtml::activePasswordField($model,'repassword',array('size'=>16,'maxlength'=>16,'value'=>$model->password)); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'name'); ?>
<?php echo EHtml::activeTextField($model,'name',array('size'=>50,'maxlength'=>50)); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'brand'); ?>
<?php echo EHtml::activeTextField($model,'brand',array('size'=>50,'maxlength'=>50)); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'address'); ?>
<?php echo EHtml::activeTextField($model,'address',array('size'=>50,'maxlength'=>50)); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'tel'); ?>
<?php echo EHtml::activeTextField($model,'tel',array('size'=>20,'maxlength'=>18)); ?>例:010-66666666-4587
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'linkman'); ?>
<?php echo EHtml::activeTextField($model,'linkman',array('size'=>7,'maxlength'=>7)); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'linkman_tel'); ?>
<?php echo EHtml::activeTextField($model,'linkman_tel',array('size'=>20,'maxlength'=>18)); ?>例:010-66666666-4587 或13901234567
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'fax'); ?>
<?php echo EHtml::activeTextField($model,'fax',array('size'=>20,'maxlength'=>18)); ?>例:010-66666666-4587
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'email'); ?>
<?php echo EHtml::activeTextField($model,'email',array('size'=>60,'maxlength'=>100)); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'qq'); ?>
<?php echo EHtml::activeTextField($model,'qq',array('size'=>10,'maxlength'=>10)); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'url'); ?>
<?php echo EHtml::activeTextField($model,'url',array('size'=>60,'maxlength'=>100)); ?>例:http://www.jiajia360.com
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'area'); ?>
<?php echo EHtml::activeDropDownList($model,'province',$areas,array('width'=>10));?>&nbsp;&nbsp;
<?php echo EHtml::activeDropDownList($model,'city',array(),array('width'=>10)); ?>&nbsp;&nbsp;
<?php echo EHtml::activeDropDownList($model,'area',array(),array('width'=>10)); ?>
</div>
<div class="simple" style="height:150px;">
<?php echo CHtml::activeLabelEx($model,'product_sort'); ?>
<table>
<tr>
	<td>
	<?php 
	foreach($sorts as $n=>$sort){
		if($sort->parent_code==''){
			if($n>0) echo '<br/>'; 
			echo $sort->name.':&nbsp;&nbsp;';
		}
		if($sort->parent_code!=''||($sort->hasChild=='' and $sort->parent_code=='')){
			$options=array('name'=>'Business[product_sort][]','value'=>$sort->code,'id'=>'Business_product_sort'.$n);
			if(is_array($model->product_sort)&&in_array($sort->code,$model->product_sort)) $options+=array('checked'=>true);
			echo CHtml::activeCheckBox($model,'product_sort',$options);
			echo '&nbsp;<a href="#" class="lab">'.$sort->name.'</a>&nbsp;&nbsp;';
		}
	}
	?>
	</td>
</tr>
</table>
</div>
<div class="simple4">
<?php echo CHtml::activeLabelEx($model,'logo'); ?>
<img id="logo_img" src='<?php echo $model->logo==''?'images/no_photo.gif':$model->logo;?>' width="170" height="90"/>
<?php
$this->widget('application.extensions.xheditor.JXHEditor', array(
      'model' => $model,
      'attribute' => 'logo',
      'options' => array(
          'width' => '30',
          'height' => '15',
		  'upImgUrl' =>'?r=business/uploadedFiles&mode=logo',//logo形式 会把下面logo(img)写入src ve防止用tab写入临时变量
		  'upImgExt' =>'jpg,jpeg,gif,png',
		  'tools' => 'Img',
		  'img_sum' => 1,//最多一张图片
		  'logo' => '#logo_img',
		  've' => '#logo1'	
      ),
      'htmlOptions' => array('readonly'=>'readonly')
  ));
?>
<input id="logo1" type="hidden" name="Business[logo1]" value="<?php echo $model->logo?>"/>
<?php //echo CHtml::button('删除图片',array('onclick'=>"$('#logo_img').attr('src','images/no_photo.gif');$('#Business_logo').val('');$('#logo1').val('');"));?>
</div>
<div class="simple4">
<?php echo CHtml::activeLabelEx($model,'introduction'); ?>(最多上传3张图片,每张小于200K.)
<?php
$this->widget('application.extensions.xheditor.JXHEditor', array(
      'model' => $model,
      'attribute' => 'introduction',
      'options' => array(
          'width' => '700',
          'height' => '400',
		  'upImgUrl' =>'?r=business/uploadedFiles&immediate=1',
		  'upImgExt' =>'jpg,jpeg,gif,png',
		  'img_sum' => 3,//最多3张图片
      ),
  ));
?>
</div>
<div class="action">
<?php echo EHtml::submitButton($update ? '更新信息' : '注册信息'); ?>
</div>

<?php echo EHtml::endForm(); ?>

</div><!-- yiiForm -->
<script>
function test(){
	alert('fsdf');
}
</script>